
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;


public class HostCommunication extends Thread{
	private ServerSocketChannel serverSocket;
	private SocketChannel clientSocket;
	private ObjectInputStream objInputStream;
	private ObjectOutputStream objOutputStream;
	
	public HostCommunication(ServerSocketChannel serverSocket){
		this.serverSocket = serverSocket;
		try {
			clientSocket = this.serverSocket.accept();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void run(){
		System.out.println("IN HOST COMM");
		try{
			InputStream in = clientSocket.socket().getInputStream();
			OutputStream out = clientSocket.socket().getOutputStream();
			
			objInputStream = new ObjectInputStream(in);
			objOutputStream = new ObjectOutputStream(out);
			
			Object incoming = objInputStream.readObject();
			
			if(incoming instanceof String){
				String input = (String)incoming;
				System.out.println(input);
			}
		}catch(Exception e){
			
		}
	}

}
